#include <iostream>
#include <stdio.h>
#include "../inc/GridFrame.h"

#ifdef __APPLE__
        #include <OpenGL/gl.h>
        #include <OpenGL/glu.h>
        #include <GLUT/glut.h>
#else
	#ifdef _WIN32
        #include "../glut.h"
	#else
        #include <GL/gl.h>
        #include <GL/glu.h>
        #include <GL/glut.h>
	#endif
#endif

using namespace std;

GridFrame::GridFrame ()
{
	bot.setXYZ(0,0,0);
	bot.setRGB(0,0,0);
	
	top.setXYZ(0,0,0);
	top.setRGB(0,0,0);
	
	cloud.clear();
}

GridFrame::GridFrame (Point _bot, Point _top)
{
	bot = _bot;
	top = _top;
	
	cloud.clear();
}

GridFrame::GridFrame (Point _bot, Point _top, PointCloud _cloud)
{
	bot = _bot;
	top = _top;
	
	cloud = _cloud;
}

int GridFrame::getSizeOfCloud()
{
	return cloud.size();
}

Point GridFrame::getBotPoint()
{
	return this->bot;
}

Point GridFrame::getTopPoint()
{
	return this->top;
}

void GridFrame::setPointBot(Point _p)
{
	bot = _p;
}

void GridFrame::setPointTop(Point _p)
{
	top = _p;
}

float GridFrame::getZMin()
{
	return cloud.getZMin();
}

Point GridFrame::getPointMin()
{
	return cloud.getPointMin();
}

void GridFrame::addPointToCloud ( Point _p )
{
	cloud.add( _p );
}

void GridFrame::displayFrame(float _z)
{
	glBegin ( GL_LINE_LOOP );
		glVertex3f ( this->bot.getX(), this->bot.getY(), _z );
		glVertex3f ( this->bot.getX(), this->top.getY(), _z );
		glVertex3f ( this->top.getX(), this->top.getY(), _z );
		glVertex3f ( this->top.getX(), this->bot.getY(), _z );
	glEnd();
}

void GridFrame::displayFrameColor()
{
	glColor3f (1,0,0);
	glBegin ( GL_QUADS );
		glVertex3f ( this->bot.getX(), this->bot.getY(), 0 );
		glVertex3f ( this->bot.getX(), this->top.getY(), 0 );
		glVertex3f ( this->top.getX(), this->top.getY(), 0 );
		glVertex3f ( this->top.getX(), this->bot.getY(), 0 );
	glEnd();
	glColor3f(1,1,1);
}

void GridFrame::displayFrameColor( float _z, float _r, float _g, float _b )
{
	glColor3f (_r,_g,_b);
	glBegin ( GL_POLYGON );
		glVertex3f ( this->bot.getX(), this->bot.getY(), _z );
		glVertex3f ( this->bot.getX(), this->top.getY(), _z );
		glVertex3f ( this->top.getX(), this->top.getY(), _z );
		glVertex3f ( this->top.getX(), this->bot.getY(), _z );
	glEnd();
	glColor3f(1,1,1);
}

void GridFrame::displayCloud()
{
	cloud.displayPointCloud();
}

void GridFrame::displayCloud(float _r, float _g, float _b)
{
	cloud.displayPointCloud(_r,_g,_b);
}

void GridFrame::display()
{
	this->displayFrame();
	this->displayCloud();
}

void GridFrame::keepPointsBetween(float _zMin, float _zMax)
{
	this->cloud.keepPointsBetween(_zMin, _zMax);
}

void GridFrame::getCircles(vector <Circle> & _tabCircles)
{
	this->cloud.getCircles( _tabCircles);
}

void GridFrame::getCircles(HoughSpace & _hs, float _rMax)
{
	this->cloud.getCircles(_hs, _rMax);
}

void GridFrame::getCircles(HoughSpace & _hs, float _rMax, int _coef)
{
	this->cloud.getCircles(_hs, _rMax, _coef);
}

void GridFrame::keepSlice(float _bas, float _haut)
{
	this->cloud.keepSlice( _bas, _haut );
}

void GridFrame::keepSlice(float _bas, int _nbPoints)
{
	this->cloud.keepSlice(_bas, _nbPoints);
}

void GridFrame::keepSlice(float _bas, float _haut, int _nbPoints)
{
	this->cloud.keepSlice(_bas, _haut, _nbPoints);
}

GridFrame GridFrame::getSlice(float _bas, float _haut)
{
	return GridFrame(bot, top, this->cloud.getSlice(_bas, _haut));
}

GridFrame GridFrame::getSlice(float _bas, int _nbPoints)
{
	return GridFrame(bot, top, this->cloud.getSlice(_bas, _nbPoints));
}

GridFrame GridFrame::getSlice(float _bas, float _haut, int _nbPoints)
{
	return GridFrame(bot, top, this->cloud.getSlice(_bas, _haut, _nbPoints));
}

void GridFrame::printBot()
{
	bot.printPoint();
}

void GridFrame::printTop()
{
	top.printPoint();
}

void GridFrame::Sort()
{
	cloud.Sort();
}
